#include "NewtonInterp.h"
#include "Function.h"

using namespace std;

int main(int argc, char* argv[]){
    
  cout << "----------------Problem B--------------------" << endl;
  vector<vector<double> > Btable[4];
  vector<vector<bool> > Bbooltable[4];
  for (int i = 1 ; i <= 4 ; i++ ){
    Btable[i-1] = BgenerateVector(2*i);
    Bbooltable[i-1] = generateBoolVector(2*i);
  }
  Polynomial<double> Bpoly[4];
  for (int i = 0 ; i < 4 ; i++ ){
    InterpConditions<double,1> BIC(Btable[i],Bbooltable[i]);
    NewtonInterp<double> BNI(BIC);
    Bpoly[i] = BNI.getInterPoly();
    cout << "N =  " << 2*(i+1) << " : " << Bpoly[i] << endl;
    string tmpstr = "N = " + to_string(2*(i+1));
  }

  cout << "----------------Problem C--------------------" << endl;
  vector<vector<double> > Ctable[4];
  vector<vector<bool> > Cbooltable[4];
  for (int i = 1 ; i <= 4 ; i++ ){
    Ctable[i-1] = CgenerateVector(5*i);
    Cbooltable[i-1] = generateBoolVector(5*i-1);
  }
  Polynomial<double> Cpoly[4];
  for (int i = 0 ; i < 4 ; i++ ){
    InterpConditions<double,1> CIC(Ctable[i],Cbooltable[i]);
    NewtonInterp<double> CNI(CIC);
    Cpoly[i] = CNI.getInterPoly();
    cout << "n =  " << 5*(i+1) << " : " << Cpoly[i] << endl;
    string tmpstr = "n = " + to_string(5*(i+1));
  }
  
  cout << "----------------Problem D--------------------" << endl;
  HermiteInterp<double,2> DHI("data/data_D");
  Polynomial<double> Dpoly = DHI.getInterPoly();
  cout << "The interpolating result:" << Dpoly << endl;
  Polynomial<double> dDpoly = Dpoly.getDerivation();
  cout << "When t = 10s , the position = " << Dpoly.getValue(10) << "(feet)"<< endl
       << "speed  = " << dDpoly.getValue(10) << "(feet per second)" << endl;
  
  cout << "----------------Problem E--------------------" << endl;
  NewtonInterp<double> ENI1("data/data_E1");
  Polynomial<double> Epoly1 = ENI1.getInterPoly();
  NewtonInterp<double> ENI2("data/data_E2");
  Polynomial<double> Epoly2 = ENI2.getInterPoly();
  cout << "For sample1, average weight curve: " << Epoly1 << endl;
  cout << "For sample2, average weight curve: " << Epoly2 << endl;
}
